package com.longg.utils;

import javax.mail.MessagingException;
import java.io.UnsupportedEncodingException;
import java.util.Random;

public class CodeUtil {
    public static String sendCode(int num,String email){
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            int n = random.nextInt(10);
            sb.append(String.valueOf(n));
        }
        try {
            MailUtil.send(email,"《小标交友》重置密码验证码",sb.toString(),MailUtil.UNICODE);
        } catch (MessagingException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println("发送邮件： " + sb.toString());
        return sb.toString();
    }
}
